<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class peneliti_model extends CI_model {
    
    function __construct() {
        parent::__construct();
        $this->load->database();
    }
    
    public function cek_penelitian_milik($penelitian,$peneliti_id){
        return TRUE;
    }


    public function cek_login($email, $pass){
        $pass_ = md5($pass);
        $query = $this->db->get_where('peneliti', array('PENELITI_EMAIL'=> $email,'PENELITI_PASSWORD'=> $pass_),1);
        if ($query->num_rows() > 0)  return $query->row();
        else return FALSE;
    }
    
    public function insert_path_foto($path,$last_id){
        $data = array(
            'PENELITI_FOTO' => $path
        );
        $this->db->where('PENELITI_ID',$last_id);
        $this->db->update('peneliti', $data);
    }
    
    public function insert_peneliti($nama,$pass,$gelardepan,$gelarbelakang,$email,$hp,$alamat,$nidn,$nip,$jurusan,$jabatan,$golongan,$kelamin,$tgl){

        $data = array(
            'PENELITI_NAMA' => $nama,
            'PENELITI_GELAR_DEPAN' => $gelardepan,
            'PENELITI_GELAR_BELAKANG' => $gelarbelakang,
            'PENELITI_EMAIL' => $email,
            'PENELITI_NOHP' => $hp,
            'PENELITI_ALAMAT' => $alamat,
            'PENELITI_NIDN' => $nidn,
            'PENELITI_NIP' => $nip,
            'JURUSAN_ID' => $jurusan,
            'PENELITI_JABATAN' => $jabatan,
            'PENELITI_GOLONGAN' => $golongan,
            'PENELITI_JENIS_KELAMIN' => $kelamin,
            'PENELITI_TGL_LAHIR' => $tgl,
            'PENELITI_PASSWORD' => md5($pass),
        );
        $this->db->insert('peneliti', $data);    
    }
    
    public function update_peneliti($peneliti_id, $nama,$gelardepan,$gelarbelakang,$email,$hp,$alamat,$nidn,$nip,$jurusan,$jabatan,$golongan,$kelamin,$tgl){
        $data = array(
            'JURUSAN_ID' => $jurusan,
            'PENELITI_NAMA' => $nama,
            'PENELITI_GELAR_DEPAN' => $gelardepan,
            'PENELITI_GELAR_BELAKANG' => $gelarbelakang,
            'PENELITI_EMAIL' => $email,
            'PENELITI_NOHP' => $hp,
            'PENELITI_ALAMAT' => $alamat,
            'PENELITI_NIDN' => $nidn,
            'PENELITI_NIP' => $nip,
            'PENELITI_JABATAN' => $jabatan,
            'PENELITI_GOLONGAN' => $golongan,
            'PENELITI_JENIS_KELAMIN' => $kelamin,
            'PENELITI_TGL_LAHIR' => $tgl,
            
        );
        $this->db->where('PENELITI_ID',$peneliti_id);
        $result = $this->db->update('PENELITI', $data);
        return $result;    
    }
    
    public function change_pwd($peneliti_id,$peneliti_email, $passold, $passnew)
    {
        $data = array(
            'PENELITI_PASSWORD' => md5($passnew), 
        );
        $this->db->where('PENELITI_ID',$peneliti_id);
        $this->db->where('PENELITI_EMAIL',$peneliti_email);
        $this->db->where('PENELITI_PASSWORD', md5($passold));
        $result = $this->db->update('PENELITI', $data);
    }
    
    public function get_peneliti($peneliti_id)
    {
        $this->db->where('PENELITI_ID',$peneliti_id);
        $query = $this->db->get('peneliti');
        return $query;
    }
    
    public function get_peneliti_all()
    {
        $query = "SELECT *
                FROM peneliti p, jurusan j
                WHERE p.jurusan_id = j.jurusan_id";
        return $this->db->query($query);
    }
    
    public function del_peneliti($peneliti_id){
        $this->db->where('PENELITI_ID', $peneliti_id);
        $this->db->delete('peneliti');
    }
    
    

}